﻿using Nova_BLL;
using Nova_Common.Extend;
using Nova_MOD;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using WMS_Api.App_Start;
using WMS_Api.Areas.RFSystem.Models;
using WMS_Api.Controllers;
using WMS_Api.Models;

namespace WMS_Api.Areas.RFSystem.Controllers
{

    /// <summary>
    /// 空托盘设置尺寸
    /// </summary>
    [RoutePrefix("api/RFSystem/EmptyTraySizeSet")]
    [ControllerGroup("PDA手持", "设置空托盘尺寸功能接口")]
    public class EmptyTraySizeSetController : BaseApiController
    {
        /// <summary>
        /// 设置空托盘尺寸
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        [HttpPost, Route("SetEmptyTraySize")]
        public ApiResult SetEmptyTraySize(SetEmptyTraySizeModel param)
        {
            TRelationsBll bll = new TRelationsBll();
            if (param.TrayId.IsEmpty())
                return Error(ResultCode.ParaError, "TrayId不能为空!");
            if (param.Size <= 0)
                return Error(ResultCode.ParaError, "Size不能为空!");
            var model = bll.GetEntityByTrayId(param.TrayId);
            //if (!model.IsEmpty() && model.Pos_ID != 200000000000)
            //    return Error(ResultCode.ParaError, "此托盘已经在立库上,无法设置尺寸!");
            bool isSet = false;
            if (model.IsEmpty())
            {
                TRelations relation = new TRelations()
                {
                    PID = Guid.NewGuid().ToString(),
                    Tray_ID = param.TrayId,
                    Pos_ID = 200000000000,
                    TypeOfSize = param.Size,
                    OID = "RFClient",
                    CDT = DateTime.Now,
                    WID = "1"
                };
                isSet = bll.InsertEntity(relation);
            }
            else
            {
                model.TypeOfSize = param.Size;
                model.CDT = DateTime.Now;
                isSet = bll.UpdateEntity(model);

            }
            return isSet ? Success("设置空托盘尺寸成功!") : Error(ResultCode.OtherError, "设置空托盘尺寸失败!");
        }
    }
}
